PHP Math issue with negatives [closed]
        Posted  
        
            by 
                user1269625
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1269625
        
        
        
        Published on 2012-08-28T14:05:06Z
        Indexed on 
            2012/08/28
            21:38 UTC
        
        
        Read the original article
        Hit count: 172
        
Possible Duplicate:
PHP negatives keep adding
I have this code here....
$remaining = 0;
foreach($array as $value=>$row){
        $remaining = $remaining + $row['remainingbalance'];
}
What its doing is that it is going through all the remaining balances in the array which are -51.75 and -17.85 with the code above I get -69.60 which is correct. But I am wondering how when its two negatives if they could subtract? Is that possible?
I tried this
$remaining = 0;
foreach($clientArrayInvoice as $value=>$row){
        $remaining = $remaining + abs($row['remainingbalance']);
}
but it gives me 69.60 without the negative.
Anyone got any ideas?
my goal is to take -51.75 and -17.85 and come up with -33.90 only when its a negative to do subtract. otherwise add
© Stack Overflow or respective owner